/**
 * 
 */
package tests.acceptanceTests;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import sourceFiles.Application;
import sourceFiles.CentralComputer;
import sourceFiles.RideState;

/**
 * @author LASO-TEAM
 * 
 *         This test that a child can exit the ride he entered the ride using
 *         his own ID.
 * 
 */
public class AcceptanceTest11 extends AcceptanceTests {

	/**
	 * @throws java.lang.Exception
	 */
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		// this initializes the relevant classes for this test.
		String currentPath = new java.io.File(".").getCanonicalPath();
		currentPath = currentPath + IN_PROJECT_PATH_TO_TESTS;
		masterXMLFilePath = currentPath + "\\input\\TestsMaster11.xml";
		copyXMLFilePath = currentPath
				+ "\\results\\AcceptanceTests11Result.xml";
	}

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		copySourceFile();
		centralComputer = new CentralComputer(copyXMLFilePath);
		application = new Application(centralComputer);
		// registering the guardian and his child, and buying a ticket for the
		// ride.
		password = centralComputer.addGuardian(IDs[0], billingInfo);
		centralComputer.addChildToGuardian(IDs[0], IDs[1], AGE, HEIGHT);
		application.login(IDs[0], password);
		application.buyTicket(1, IDs[0], IDs[1]);
		// getting the ride that we wish to enter.
		ride = centralComputer.getRidesList().getFirst();
		// the child enters the ride.
		ride.childEntersRide(IDs[1]);
	}

	@Test
	public void test() {
		try {
			//waiting until we can exit the ride.
			while (!ride.getState().equals(RideState.STANDBY)
					&& !ride.getExitGate().IsGateOpened()) {
			}
			//trying to exit the ride.
			ride.childExitsRide(IDs[1]);
		} catch (Exception e) {
			fail("supposed to succeed. " + e.getClass().toString());
		}
	}

}
